<?php

error_reporting(E_ALL);
$relPath='./pinc/';

require_once $relPath."dpinit.php";
require_once $relPath."dp_main.inc";

$projectid      = ArgProjectId();
$todo           = Arg("todo");

// ---------------------------------------------------------

$projectid != ""
    or die(_("Please specify a projectid."));

$project = new DpProject($projectid);
$project->Exists()
    or die(_("Please specify a projectid for an existing project."));


$title = $project->Title() . _(': project page');
$page_title = $project->Author().": ".$project->Title()
    ." (".$project->LanguageName().")";
theme_header($title);

// ---------------------------------------------------------

if(! $User->IsLoggedIn()) {
    echo "<h2>$page_title</h2>\n";
    echo_project_info($project);
    theme_footer();
    exit;
}

$User->SetLatestVisit($project->ProjectId());

if($project->UserMayManage() && $todo == "toggle_avail") {
    $project->ToggleAvailable();
    $project = new DpProject($projectid);
}

echo "
<div class='center w100'>
<h2>$page_title</h2>\n";

if($project->UserMayManage() && $project->BadCount() > 0) {
    echo"<h3 class='red'>". _("PM message - pages marked bad: ")
                    ."{$project->BadCount()}</h3>\n";
}

// 3
echo "
<div class='note center padded margined'>\n";
info_note($project);
top_note($project);
echo "
</div>\n";

// 5
if($project->UserMayManage()) {
    echo "
    <div class='linkdiv'>
    ".link_to_edit_project($projectid, "Edit project")."
    ".link_to_project_words($projectid, "Manage words")."
    ".link_to_project_files($projectid, "Manage files")."
    ".link_to_clone_project($projectid, "Clone project")."
    ".link_to_downloads($projectid, "Download")."
    </div>\n";
}

echo_project_info($project);

if($project->PPVer() == $User->Username()) {
    echo " <div class='w50'>\n";
    echo_ppv_report($project);
    echo "</div>\n";
}

echo " <div class='w50'>\n";
echo_history($project);
echo "</div>\n";

echo "</div>\n";


theme_footer();
exit;

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function info_note($project) {
    $projectid = $project->ProjectId();
    $state = $project->State();

    if(! $project->UserMayProof()) {
        echo _("This project is not available to you.");
    }

    if($project->IsRoundCompleted()) {
        echo _("Task Complete.");
    }
    if(! $project->IsAvailable()) {
        echo _("There are no pages currently available.");
    }
}
    // ------------------------------------------------------------

function top_note($project) {
    echo_status_bar($project);

    if ($project->MostRecentUserProofDate() == ""
            && $project->LastCommentChangeTime()
                    > $project->MostRecentUserProofDate()) {
        if ($project->MostRecentUserProofDate() != "") {
            echo "
                <div class='red'>" 
                . _("Project Comments have changed!") 
                . "</div>\n";
        }
    }

    if(($n = $project->UserCheckedOutPageCount()) > 0) {
        echo _("There are $n pages checked out to you.");
    }
    if($project->IsAvailableForActiveUser()) {
        echo link_to_proof_next($project->ProjectId(), 
                                    "Start Proofreading");
    }
}

// ------------------------------------------------------------------

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_project_info($project) {
    global $code_url, $wc_url;
    global $pm_url;
    global $dpdb;
    global $User;
    global $Context;

    $projectid = $project->ProjectId();

    echo "<table id='project_info_table'>\n";

    // --------------------------------------------------------------


    $roundid = $project->RoundId();
    $right = "<span class='lfloat'>"
        .$project->RoundIdName() . " - " 
        .$project->AvailableMessageForActiveUser();

    if($project->IsAvailableForSmoothReading()) {
        $sr_deadline_str = std_date($project->SmoothReadDeadline());
        $sr_sentence = sprintf(
            _('This project has been made available 
                for smooth reading until %s.'), "$sr_deadline_str");
        $extra2 = _('See below.');
        $right = "$right<br>$sr_sentence $extra2";
    }
    $right .= "\n</span>\n";
    if($project->UserMayManage()) {
        $right .= echo_status_checkbox($project);
    }

    echo_left_right( "Status", $right );

    if ( $project->State() == PROJ_DELETE ) {
        // Change anything that looks like a projectid into a link.
        $reason = $project->DeletionReason() ;
        echo_left_right( "Reason for deletion", $reason );
    }

    // ------------------------------------------------------------
    // Information about the work itself (independent of DP)
    
    // the array below should guarantee that the strings 'beginner',
    // 'easy', 'average' and 'hard' reach the po file, so that using
    // later _($project->difficulty) should translate the project
    // difficulty, if regularly formed, or display the (irregular)
    // english project difficulty.

    echo_left_right( "Title",             $project->Title());
    echo_left_right( "Author",            $project->Author());
    echo_left_right( "Primary language",  $project->LanguageName());
    echo_left_right( "Other languages",   
                                    $project->OtherLanguageCodes());
    echo_left_right( "Genre",             _($project->Genre()));
    echo_left_right( "Task",        _($project->Difficulty()));

    // ------------------------------------------------------------
    // Basic DP info


    echo_left_right( "Project ID", $project->ProjectId() );

    // The clearance line contains the email address of the
    // person who submitted the clearance request. Since this is
    // private information, we restrict who can see it.
    if($project->UserMayManage()) {
        $titlepagelink = (
            $project->TitlePage()
                ? link_to_display_image($project->ProjectId(),  
                        $project->TitlePage(), 
                        $project->TitlePage(),
                        true)
            : "(na)"
        );

        $str = $project->Clearance();
        $str = preg_replace("/\n/", "<br />", $str);
        echo_left_right("Clearance line", $str);
        echo_left_right("Title page", $titlepagelink);
    }

    // -----------------------------------------------------------
    // People who have certain roles with respect to the project

    $imgsrc = $project->ImageSource();
    if (!empty($imgsrc)) {
        echo_left_right( "Image source", h($imgsrc) );
    }

    echo_left_right( "Project manager", $project->PM() );

    if ( $project->PPer()) {
        echo_left_right( "Post-processor", $project->PPer() );
    }

    if ($project->PPVer()) {
        echo_left_right( "PP verifier", $project->PPVer() );
    }

    echo_left_right( "Credits line", h($project->Credits()) );

    // -----------------------------------------------------------
    // Current activity

    $formatted_now = std_time(time());
    $ct = _("current time");
    $current_time_addition = "&nbsp;&nbsp;($ct: $formatted_now)";

    echo_left_right( "Project info edited",
        std_datetime($project->LastEditTime())
        . $current_time_addition );


    $proofdate = $project->MostRecentSavePageDate();
    $lastproofed = (empty($proofdate)
            ? _("This task has not been performed yet.")
            : std_datetime( $proofdate)
    );
    echo_left_right( "Last page saved", $lastproofed );

    // -----------------------------------------------------------

    if($project->PostedNumber() != "") {
        echo_left_right( 
            "PG etext number",
            $project->PostedNumber() . " &ndash; " .
            sprintf(_("<a href='%s'>Read this text</a>
                                at Project Gutenberg"),
                 get_pg_catalog_url_for_etext($postednum)));
    }

    // -----------------------------------------------------------
    // Forum topic

    if ($project->LastForumPostDate() != "") {
        echo_left_right( 
            "Last forum entry",
            std_datetime($project->LastForumPostDate())
        );
    }

    // If the topic is only visible to logged-in users,
    // there's little point showing guests the link to it.
    $note = ($project->ForumTopicIsEmpty()
        ? _("Start a discussion about this project")
        : _("Discuss this project")
    );
    
    echo_left_right("Forum", 
    "<a href='{$project->ForumTopicUrl()}'>$note</a>");

    // -----------------------------------------------------------

    $linkpages =
        link_to_page_detail($projectid, "View pages (diffs)", true);
    $linkmypages = 
        link_to_page_detail_mine(
                            $projectid, "View my pages (diffs)");

    $rightstr = "
    <form name='pagesform' id='pagesform' method='POST'
                                        accept-charset='UTF-8'>
    <div class='lfloat center w50' style='margin:0'>$linkpages</div>
    <div class='lfloat center w50' style='margin:0'>$linkmypages</div>
    </form>\n";

    echo_left_right( "Project pages", $rightstr);

// Personal data with respect to this project

    if($project->IsAvailableState())
    {
        echo_my_pages($project);
    }

// ------------------------------------------------------------

// Show postcomments to those involved with the project (the
// first three conditions). For PPVing, the prospective
// PPVer can read the PPer's comments here.
// when it's available for PPing, a prospective PPer can read them

    $postcomments = $project->PostComments();

    if ($postcomments != '')
    {
        if($project->IsAvailableForSmoothReading())
        {
            echo_one_row( _("Smooth reading instructions"));
            echo_one_row( $postcomments);
        }
        elseif($project->UserMayManage() 
                 || ($state == PROJ_POST_FIRST_AVAILABLE 
                                && $User->MayWorkInRound('PP')) 
                 || ($state==PROJ_POST_SECOND_AVAILABLE 
                                && $User->MayWorkInRound('PPV')))
        {
            echo_one_row(_("Post Processor's Comments"));
            echo_one_row($postcomments);
        }
    }

    echo "</table>\n";

// Comments

    // -------------------------------------------------------

    // Suppress Project Comments for guests.

    $comments = $project->Comments();

    // insert e.g. templates and biographies

    if($comments != "") {
        $changetime 
            = std_datetime($project->LastCommentChangeTime());

        echo "
        <div class='w50 left padded'>
        <div class='left bold margined'>"._("Project comments:")."</div>
        $comments
        <div class='center'>"
            ._("(Comments modified {$changetime})")."
        </div>
        </div>\n";
    }
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_left_right( $left, $right) {
    $left = _($left);
    echo "
    <tr>
        <td class='left_cell'>$left</td>
        <td class='right_cell' colspan='4'>$right</td>
    </tr>\n";
}

function echo_two_rows( $top, $bottom, $class = null) {
    $style = ($bgcolor
                ? "style='background-color: $bgcolor;'"
                : "");

    echo "
    <tr><td class='center padded' colspan='5' $style>
    $top
    <br />
    $bottom
    </td></tr>\n";
}

function echo_one_row( $content, $bgcolor = null ) {
    $style = ($bgcolor 
                ? "style='background-color: $bgcolor;'" 
                : "");

    echo "
    <tr><td colspan='5' $style>
        $content
    </td></tr>\n";
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_my_pages($project) {
    $rows = $project->ActiveUserUncompletedPages(5);
    if(count($rows) > 0) {
        echo "
        <tr><td class='my_pages_open left_cell'>
        "._("My incomplete pages")."</td>
        <td colspan='4' class='my_pages_open'>\n";
        echo_page_cells($rows);
        echo "
        </td></tr>\n";
    }

    $rows = $project->ActiveUserCompletedPages(5);
    if(count($rows) > 0) {
        echo "
        <tr><td class='my_pages_saved left_cell'>
        ". _("My completed pages")."</td>
        <td colspan='4' class='my_pages_saved'>\n";
        echo_page_cells($rows);
        echo "
        </td></tr>\n";
    }
}

function echo_page_cells($rows) {
    global $proof_url;

    if(empty($rows)) {
        echo "
            <div class='recent'>&nbsp;</div>
            <div class='recent'>&nbsp;</div>
            <div class='recent'>&nbsp;</div>
            <div class='recent'>&nbsp;</div>
            <div class='recent'>&nbsp;</div>\n";
        return;
    }


    for($i = 0; $i < 5; $i++) {

        if($i < count($rows)) {
            $row = $rows[$i];
            $projectid  = $row["projectid"];
            $pagename   = $row["pagename"];
            $roundtime  = $row["roundtime"];
            $page_state = $row["page_state"];
            $status = preg_replace("/^.+?_/", "", 
                                    $row["page_state"]);
                    
            $eURL = url_for_proof_page($projectid, $pagename);
            echo "  
                <div class='recent'>
                <a href='$eURL'>"
                        .Month_day($roundtime)
                        .":<br>p. $pagename</a></div>\n";
        }
        else {
            echo "<div class='recent'>&nbsp;</div>\n";
        }
    }
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_edit_project($project) {
    $projectid = $project->ProjectId();

    if($project->UserMayManage()) {
        echo "
            <div class='linkdiv'>
            ".link_to_edit_project($projectid, "Edit project")."
            ".link_to_project_words($projectid, "Manage words")."
            ".link_to_project_files($projectid, "Manage files")."
            ".link_to_clone_project($projectid, "Clone project")."
            </div>\n";
    }
}


function echo_history($project) {

    echo "<div class='left top bold margined'>", _("Project History"), "</div>\n";

    $rows = $project->EventHistory();
    if(count($rows) == 0)
    {
        echo _("<p>No history available yet.</p>");
        return;
    }

    $tbl = new DpTable();
    $tbl->AddColumn("^Date/Time", "event_time", "yy_mm_dd_hh_nn");
    $tbl->AddColumn(_("<Who"), "who");
    $tbl->AddColumn(_("<Type"), "event_type");
    $tbl->AddColumn(_("<Note"), "note");
    $tbl->SetRows($rows);
    $tbl->EchoTable();
}

function event_time($val) {
    return yy_mm_dd_hh_nn_ss($val);
}


function echo_extra_files($project) {
    global $User;
    $username = $User->UserName();

    $saved_dir = getcwd();
    chdir($project->ProjectPath());
    $filenames = glob("*" );
    $n_extra_files = 0;

    echo "
        <h3>". _('Extra Files in Project Directory'). "</h3>
        <div>";

    foreach ($filenames as $filename) {
        if ( is_an_extra_file($project, $filename) ) {
            echo "
                <p><a href='{$project->ProjectUrl()}/$filename'
                    target='_blank'>
                    $filename</a></p>\n";
            $n_extra_files++;
        }
    }

    if ( $n_extra_files == 0 ) {
        echo "<p>", _("(none)"), "</p>\n";
    }

    echo "</div>\n";

    chdir($saved_dir);
}

function is_an_extra_file($project, $filename ) {
    global $is_wordcheck;

    static $excluded_filenames = NULL;
    if ( empty($excluded_filenames) ) {
        $excluded_filenames = array();
        // A small set of filenames to exclude a priori.
        
        if($is_wordcheck) {
        // These appear at "Word Lists":
            foreach ( array('good', 'bad') as $code )
            {
                $f = get_project_word_file($project->ProjectId(), 
                    $code);
                $excluded_filenames[$f->filename] = 1;
            }
        }

        // These three appear under "Post Downloads":
        $excluded_filenames[$project->ProjectId().'images.zip'] = 1;
        $excluded_filenames[$project->ProjectId().'.zip'] = 1;
        $excluded_filenames[$project->ProjectId().'_TEI.zip'] = 1;

        // should exclude uploaded SR, PP and PPV files too,
        // but we can't add them to excluded_filenames because we
        // don't know their names in advance
    }

    if ( array_key_exists( $filename, $excluded_filenames ) )
        return FALSE;

    // Exclude all images (both page-images and non-page-images).
    $image_extensions = array('png','jpg');
    $extension = pathinfo($filename,PATHINFO_EXTENSION);
    if ( in_array($extension, $image_extensions) )
        return FALSE;

    return TRUE;
}

function echo_uploaded_zips($project, $discrim, $upload_type) {

    $done_files = glob("{$project->ProjectPath()}/*"
                              .$discrim."*.zip");
    if ($done_files) {
      echo sprintf( _
        ("Download %s file uploaded by:"), $upload_type);
      echo "<div>";
      foreach ($done_files as $filename) {
          $showname = basename($filename,".zip");
          $showname = substr($showname, 
            strpos($showname,$discrim) 
                + strlen($discrim));
          echo_download_zip($project, $showname, $discrim. $showname);
        }
      echo "</div>";
    }
  else {
      echo sprintf( 
            _("No %s results have been uploaded."), $upload_type);
    }

}
// ------------------------------------------------------------

function echo_download_zip($project, $link_text, $discrim) {
    global $code_url;
    global $tools_url;

    $projectid = $project->ProjectId();
    if ( $discrim== 'images' ) {
        $url = "$tools_url/download_images.php"
                ."?projectid=$projectid"
                ."&dummy={$projectid}images.zip";
        $filesize_b = 0;
        foreach( 
            glob("{$project->ProjectPath()}/*.{png,jpg}",
                    GLOB_BRACE) as $image_path ) {
            $filesize_b += filesize($image_path);
        }
        $filesize_kb = round( $filesize_b / 1024 );
    }
    else {
        $p = "{$projectid}{$discrim}.zip";

        $url = "{$project->ProjectUrl()}/$p";
        $filesize_kb = round( 
            filesize( "{$project->ProjectPath()}/$p") / 1024 );
    }

    echo "
        <p><a href='$url' target='_blank'>$link_text</a> ("
        .sprintf(_("%d kb"), $filesize_kb).")
        </p>\n";
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_postcomments($project) {
    global $code_url, $forums_url;
    global $User;


    $projectid = $project->ProjectId();

    if ($project->UserIsPPer()) {

      // Give the PP-er a chance to update the project record
      // (limit of 90 days is mentioned below).
      echo "
          <h3>" . _("Post-Processor's Comments") . "</h3>
          <p>"
          .sprintf(_(
        "You can use this input box to enter how you're
        doing with the post-processing, for yourself and
        so we know that there's still work in progress.
        You will not receive a reminder about this project 
        for at least another %1\$d days.
        You can use this feature to keep track of missing pages,
        etc. If you are waiting on missing images or page
        scans, add the details to the <a href='%2\$s'>Missing Page
        Wiki</a>. Your old comments will be replaced by those
        you enter here."),
                90,
                "{$forums_url}/viewtopic.php?t=7584")."
        </p>
      <form name='pp_update' accept-charset='UTF-8' method='post' 
            action='$code_url/tools/post_proofers/postcomments.php'>
      <textarea name='postcomments' cols='60' rows='6'>
          ".h($project->PostComments())."
      </textarea>
      <input type='hidden' name='projectid' value='$projectid' />
      <br /><input type='submit' value='" 
      . _z('Update comment and project status') . "'/>
      </form>\n";
    }
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_smooth_reading($project) {
    global $code_url;
    global $User;


    $projectid = $project->ProjectId();

    $current_user_can_manage_SR_for_this_project =
        ($project->PPer() == $User->Username() 
            || $User->IsSiteManager());
    // i.e., can:
    // -- make the project available for SR (initially or again),
    // -- replace the SR-able text,
    // -- see SR-commitments, and
    // -- read SR'ed texts

    echo "<h3>"._('Smooth Reading')."</h3>\n";

    if ( ! $project->SmoothReadDeadline())
    {
        echo "
        <p>". _('This project has not been made available for
            smooth reading.')."
        </p>";

        if ($current_user_can_manage_SR_for_this_project)
        {
            echo "
            <p>\n"
            . _("But you can make it available. Choose how
                long you want to make it available.")."</p>
            ";
            $link_start = "<a
                href='{$code_url}/tools/upload_text.php"
                ."?projectid=$projectid"
                ."&stage=smooth_avail"
                ."&weeks'";
            echo "<div>
                <p>$link_start=1'>"._("one week")."</a></p>
                <p>$link_start=2'>"._("two weeks")."</a></p>
                <p>$link_start=4'>"._("four weeks")."</a></p>
            </div>
            \n";
        }

    }
    else
    {
        // Project has been made available for SR

        if ( time() < $project->SpeedReadDeadline() )
        {
            $sr_deadline_str 
                = std_date($project->SpeedReadDeadline() );
            $sr_sentence = sprintf(
                _('This project has been made available 
                        for smooth reading until %s.'),
                "$sr_deadline_str"
            );

            echo "<p>";
            echo $sr_sentence;
            echo "</p>\n";

            if ($current_user_can_manage_SR_for_this_project)
            {
                echo "
            <p>
            <a href='$code_url/tools/upload_text.php"
                    ."?projectid=$projectid"
                    ."&stage=smooth_avail"
                    ."&weeks=replace'>
                ". _("Replace the current file that's available for smooth-reading.")."</a>
                </p>\n";
            }

            if ($project->PPer() != $User->Username())
            {
                echo_download_zip($project,  
                _("Download zipped text for smooth reading"), 
                '_smooth_avail' );
                
            // Don't allow guests to upload results smooth-reading.
                if ( $User->IsLoggedOn() )
                {
                    echo "<p>";
                    echo "<a href='$code_url/tools/upload_text.php"
                            ."?projectid=$projectid"
                            ."&stage=smooth_done'>";
                    echo _("Upload a smooth-read text") ;
                    echo "</a>";
                    echo "</p>\n";
                    // Upload does not change project state --
                    // it's still checked out to PPer.

                    if ($User->IsLoggedIn()  
                    && !sr_user_is_committed($projectid, $pguser))
                    {
                        echo "<p>";
                        echo _('If you want, you can indicate 
                            your commitment to smoothread this 
                            project to the PP by pressing:');
                        sr_echo_commitment_form($projectid);
                        echo "</p>\n";
                    }
                    else
                    {
                        echo "<p>";
                        echo _('You have committed to 
                                moothread this project.');
                        echo "<br />";
                        echo _('If you want to withdraw your 
                                commitment, please press:');
                        sr_echo_withdrawal_form($projectid);
                        echo "</p>";
                    }
                }
                else
                {
                    echo "<p>";
                    echo _('Please note that while unregistered 
                    guests are welcome to download texts for 
                    smooth reading, only registered volunteers 
                    are able to upload annotated texts.');
                    echo "\n";
                    echo _('A registration link is available 
                        at the top of this page.');
                    echo "</p>\n";
                }
            }
        }
        else
        {
            echo "<p>";
            echo _('The deadline for smooth-reading this project 
                    has passed.');
            echo "</p>";

            if ($current_user_can_manage_SR_for_this_project)
            {
                echo "<p>";
                echo _("But you can make it available for 
                        mooth-reading for a further period.")." ";
                echo _('Choose how long you want to make it 
                        vailable for.');
                $link_start = "<a
                    href='$code_url/tools/upload_text.php"
                            ."?projectid=$projectid"
                            ."&stage=smooth_avail"
                            ."&weeks'";
                echo "<div>";
                    echo "<p>$link_start=1'>"._("one week")."</a>";
                    echo "<p>$link_start=2'>"._("two weeks")."</a>";
                    echo "<p>$link_start=4'>"._("four weeks")."</a>";
                echo "</div>";
                echo "</p>\n";
            }


        }

        if ($current_user_can_manage_SR_for_this_project)
        {

            $sr_list = sr_get_committed_users($projectid);

            echo "<p>";
            if (count($sr_list) == 0)
            {
                echo _('Nobody has committed
                        to smoothread this project.');
            }
            else
            {
                echo _('The following users have committed 
                        o smoothread this project:');
                echo "<div>";
                foreach ($sr_list as $sr_user)
                {
                    $user_privmsg_url 
                    = get_url_to_compose_message_to_user($sr_user);
                    echo "<p>";
                    echo "<a href='$user_privmsg_url'>$sr_user</a>";
                    echo "</p>\n";
                }
                echo "</div>\n";
            }

            echo_uploaded_zips($project,
                    '_smooth_done_',
                    _('smoothread'));
        }
    }
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_ppv_report($project) {
    global $code_url;


    $url = "$code_url/tools/post_proofers/ppv_report.php"
                    ."?projectid={$project->ProjectId()}";
    echo "<p><a href='$url'>"
        ._("Submit a PPV Summary for this project")
        ."</a></p>";
}


function echo_status_bar($project) {
    $completed   = $project->CompletedCount();
    $available   = $project->AvailableCount();
    $out         = $project->CheckedOutCount();
    $temp        = $project->TempCount();
    $total       = $project->PageCount();
    // $inprogress  = $project->InProgressCount();

    echo "
    <!-- 
    c:{$project->CompletedPercent()}
    o:{$project->CheckedOutPercent()}
    t:{$project->TempPercent()}
    a:{$project->AvailablePercent()} ({$project->PageCount()})
    -->
    <div class='status_bar'>
    <span>Total {$total} pages:</span>
    <span class='pg_completed side_padded'>
                        completed ({$completed})</span>
    <span class='pg_unavail side_padded'>
                    out/temp ({$out}/{$temp})</span>
    <span class='pg_avail side_padded'>
                        Available ({$available})</span>
    </div>\n";
}

function echo_status_checkbox($project) {
    $projectid = $project->ProjectId();
    $roundid = $project->RoundId();
    $state = $project->State();
    $isavail = $project->IsAvailableState();
    return "
    <form class='inline rfloat' name='statusform' action=''
            accept-charset='UTF-8' method='POST'>
        <input type='hidden' name='projectid' value='$projectid'>
        <input type='hidden' name='todo' value='toggle_avail'>
        <input type='button' name='btnavail'
        value='".($isavail ? "Set unavailable" : "Set available")
            ."' onclick='this.form.submit()'>
    </form>\n";
}

// vim: sw=4 ts=4 expandtab
?>
